<div id="main">
    <!-- 购物车开始 -->

    <h1><{t}>购物车<{/t}></h1>

    <{if $is_empty}>
    <{include file="site/cart/cart_empty.html" app=b2c}>
    <{else}>
    <!-- 购物车步骤图 -->
    <!--<div id="cart_steps" class="steps">
      <table width="100%">
        <tbody>
          <tr>
            <td class="step-item step-1 active"><span><q class="icon">&#x50;</q><i>1</i>购物车</span></td>
            <td class="icon step-arrow">&#x28;</td>
            <td class="step-item step-2"><a href="<{link app=b2c ctl=site_cart act=checkout}>"><q class="icon">&#x50;</q><i>2</i>填写和提交订单信息</a></td>
            <td class="icon step-arrow">&#x28;</td>
            <td class="step-item step-3"><span><q class="icon">&#x50;</q><i>3</i>成功提交订单</span></td>
          </tr>
        </tbody>
      </table>
    </div>-->
    <div class="cart-steps">
        <div class="step active"><{t}>我的购物车<{/t}></div>
        <div class="steps-separator"><span class="glyphicon glyphicon-arrow-right"></span></div>
        <div class="step"><{t}>填写订单信息<{/t}></div>
        <div class="steps-separator"><span class="glyphicon glyphicon-arrow-right"></span></div>
        <div class="step"><{t}>完成订单<{/t}></div>
        <div class="clearfix"></div>
    </div>
    <!--  ==================================  添加商品类别条数---珍珍================================================-->
    <p><b><{t}>Всего моделей:<{/t}> <span  id="line_lenth"></span></b></p>
    <!--  ==================================  添加商品类别条数---珍珍  end================================================-->
    <p><b><{t}>Всего товаров:<{/t}><i class="change_car"><{$aCart.items_quantity}></i><{t}>件商品了<{/t}></b></p>


    <div class="clear_float"></div>
    <!-- 总体积总重量注释 -->
    <!--<div class="or_gai text-right"><{t}>总体积：<{/t}> <span class="total_capacity"><{$aCart.subtotal_capacity}></span>m³; <{t}>总重量：<{/t}> <span class="total_weight"><{$aCart.subtotal_weight}></span>kg</div>-->
    <!-- 购物车主体 -->
    <div id="cart_container" class="cart-container noauto">
        <{include file="site/cart/cart_main.html" app=b2c}>
    </div>
    <{/if}>
	
	<div data-retailrocket-markup-block="5846963865bf1912a4e3c477" data-products-id="<{foreach from=$aCart.object.goods item=goods key=_obj_key name=goods}><{if $smarty.foreach.goods.last}><{$goods.obj_items.products.0.goods_id}><{else}><{$goods.obj_items.products.0.goods_id}>,<{/if}>	<{/foreach}>"></div>

    <!-- 浏览过的商品 -->
    <{include file="site/cart/view_history.html" app=b2c}>
</div>

<script type="text/javascript">
    //========================================================== 新添加购物车条数的js============================================================
    function linnum(){
        var _numb=jQuery('.cart-item').length;
        jQuery("#line_lenth").html(_numb);
    }
    linnum();
    function change_num(){
        var change_num = 0;
        jQuery('.p-quantity input').each(function(){
            change_num+=parseInt(jQuery(this).val());
        });
        jQuery('.change_car').text(change_num);
    }

    //========================================================== 新添加购物车条数的js end=================
    (function() {



        <{if $is_pre}>
            jQuery('.presalebox').find('input[type=checkbox]').each(function(){
                jQuery(this).prop({checked: true});
            });
            jQuery('.presalebox').siblings('div').find('input[type=checkbox]').each(function(){
                jQuery(this).prop({checked:false});
            });
        <{else}>
            jQuery('.presalebox').find('input[type=checkbox]').each(function(){
                jQuery(this).prop({checked: false});
            });
            jQuery('.presalebox').siblings('div').find('input[type=checkbox]').each(function(){
                jQuery(this).prop({checked:true});
            });
            if(jQuery('.table-responsive').length==2 &&  jQuery('.presalebox').length>0){
                jQuery('.presalebox').find('input[type=checkbox]').each(function(){
                    jQuery(this).prop({checked: true});
                });
            }
        <{/if}>

        jQuery('.changeno').click(function(){
            if( jQuery(this).children('i').attr('class').indexOf('glyphicon-triangle-top')>0){
                jQuery(this).children('i').removeClass('glyphicon-triangle-top').addClass('glyphicon-triangle-bottom');
                jQuery(this).parent().siblings('table').hide();
                jQuery(this).parents('.table-responsive').find('input[type=checkbox]').each(function(){
                    jQuery(this).prop({checked:false});
                });
                jQuery(this).parents('.table-responsive').siblings('div').find('input[type=checkbox]').each(function(){
                    jQuery(this).prop({checked:true});
                });
                //---------
                var obj_idents = cart_obj_check();
                new Request({
                    url:'<{link app=b2c ctl=site_cart act=cart_obj_all_checked}>',
                    data: "obj_idents="+obj_idents+"&response_json=true",
                    onComplete: function(rs){
                        rs = JSON.decode(rs);
                        if(rs.success) {
                            updateCart(rs);
                        }
                    }
                }).post();
                //---------
                jQuery(this).children('span').text('Показать');
                jQuery(this).parents('.table-responsive').siblings('.table-responsive').children('.table').show();
                jQuery(this).parents('.table-responsive').siblings('.table-responsive').find('.changeno i').removeClass('glyphicon-triangle-bottom').addClass('glyphicon-triangle-top');
                jQuery(this).parents('.table-responsive').siblings('.table-responsive').find('.changeno span').text('Свернуть');
            }else{
                jQuery(this).children('span').text('Свернуть');
                jQuery(this).children('i').removeClass('glyphicon-triangle-bottom').addClass('glyphicon-triangle-top');
                jQuery(this).parent().siblings('table').show();
                if(jQuery('.table-responsive').length==2){
                    jQuery(this).parents('.table-responsive').find('input[type=checkbox]').each(function(){
                        jQuery(this).prop({checked:true});
                    });
                    //---------
                    var obj_idents = cart_obj_check();
                    new Request({
                        url:'<{link app=b2c ctl=site_cart act=cart_obj_all_checked}>',
                        data: "obj_idents="+obj_idents+"&response_json=true",
                        onComplete: function(rs){
                            rs = JSON.decode(rs);
                            if(rs.success) {
                                updateCart(rs);
                            }
                        }
                    }).post();
                    //---------
                }
            }
        });
//  ===============================列表页面图片变大效果=======================================================
                    jQuery(".cart-main tr td .p-pic").hover(function(){
                        var owntop=jQuery(window).height()-(jQuery(this).offset().top - jQuery(document).scrollTop()+50);
                        var new_img= jQuery(this).clone();
                        jQuery(this).parent().append(new_img);

                        if(owntop>160){
                            jQuery(this).siblings('.p-pic').addClass('letbig').stop().animate({width:160, height:160,top:58,left:60},0);
                        }else{
                            jQuery(this).siblings('.p-pic').addClass('letbig').stop().animate({width:160, height:160,top:-154,left:60},0);
                        }
                    },function(){
                        jQuery(this).siblings('.p-pic').remove();
                    });
        <{if !$is_empty}>
        <{if $money_format}>
        priceControl.spec = <{$money_format}>;
        <{/if}>
        var container = $('cart_container');
        var typeJSON = {
            'product': ['<{t}>商品<{/t}>', '<{t}>购买<{/t}>'],
            'packs': ['<{t}>礼包<{/t}>', '<{t}>购买<{/t}>'],
            'exchange': ['<{t}>赠品<{/t}>', '<{t}>兑换<{/t}>']
        };

        //= 获取商品属性值
        function getTypeValue(type) {
            if(!type) return null;
            var value = typeJSON[type];
            if(typeof value == 'string') value = [value, '<{t}>购买<{/t}>'];
            return {name:value[0], mode: value[1]};
        }
        //== 商品数量输入框正确性检测
        function inputCheck(input, options) {
            if(!input) return false;
            options = options || {};
            if(isNaN(options.min)) options.min = 1;
            if(isNaN(options.max)) options.max = 9999;
            options.type = options.type || 'product';
            options['default'] = options['default'] || options.min;
            var info = getTypeValue(options.type);
            var value = +input.value;
            var tips = new Tips(input);
            var pre = '';
            var msg = '';
            if(options.store && options.store - value <= 0) {
                pre = '<{t}>库存有限，<{/t}>';
            }
            if(value < options.min) {
                input.value = options.min;
                msg = '<{t}>此<{/t}>' + info.name + '<{t}>的最小<{/t}>' + info.mode + '<{t}>数量为<{/t}>' + options.min + '<{t}>件<{/t}>';
            }
            else if(value > options.max){
                input.value = options.max;
                msg = pre + '<{t}>此<{/t}>' + info.name + '<{t}>最多只能<{/t}>' + info.mode + options.max + '<{t}>件<{/t}>';
            }
            else if(isNaN(value)) {
                input.value = options['default'];
                msg = '<{t}>只允许输入数字<{/t}>';
            }
            if (msg) {
                tips.show(msg);
                return false;
            }
            tips.hide();
            //warn.hide();
            if(options.type == 'packs') {
                input.getParent('.cart-item').getElements('.p-packs-item .p-num').set('text', value);
            }
            input.value = parseInt(value);
            return true;
        }
        //== 获取商品数量值
        function getQuantity(el, type) {
            return el.getElement('input[name=' + type + ']').value;
        }
        //== 设置商品数量
        function setQuantity(input, value) {
            var type = input.getParent('.p-packs') ? 'packs' : input.getParent('.cart-exchange') ? 'exchange' : 'product';
            var typeName = typeJSON[type];
            var p = input.getParent('tr');
            if(!inputCheck(input, {min: getQuantity(p, 'min'), max: getQuantity(p, 'max'), 'default': value, type: type, store: getQuantity(p, 'stock')}) && input.value == value) {
                return;
            }
            //edit yhy
            var obj_idents=cart_obj_check();
            new Request({
                url: '<{link app=b2c act=update ctl=site_cart}>',
                data: p.toQueryString()+"&obj_idents="+obj_idents+"&response_json=true",
                onComplete: function(rs){
                    rs = JSON.decode(rs);
                    if(rs.success) {
                        updateCart(rs, p);
                        //console.log(rs);
                    }
                }
            }).post();
            change_num();
        }
        //== 更新购物车信息统一入口
        function updateCart(rs, p){
            if(!rs) return;
            if(!rs.promotion)rs.promotion = {};
            if(p) {
                updateGoodsInfo(rs, p);
                updateGoodsPromotion(rs.promotion.goods, p);
            }
            console.log(rs);
            updateOrderInfo(rs.sub_total);
            updateOrderGift(rs.order_gift);
        <{if $cart_promotion_display == 'true'}>
            updateOrderPromotion(rs.promotion.order);
            updateUnusePromotion(rs.unuse_rule);
        <{/if}>
            updateCartInfo();
            //总体积 by yyj 2015/12/23
            if(rs.subtotal_capacity){
                updateSubtotalCapacity(rs.subtotal_capacity);
            }
            //总重量 by yyj 2015/12/23
            if(rs.subtotal_weight){
                updateSubtotalWeight(rs.subtotal_weight);
            }
        }
        //== 总体积 by yyj 2015/12/23
        function updateSubtotalCapacity(subtotal_capacity) {
            if(!subtotal_capacity) return;
            try{
                $$('.total_capacity').set('html',subtotal_capacity ? subtotal_capacity : '0');
            }catch(e){}
        }
        //== 总重量 by yyj 2015/12/23
        function updateSubtotalWeight(subtotal_weight) {
            if(!subtotal_weight) return;
            try{
                $$('.total_weight').set('html',subtotal_weight ? subtotal_weight : '0');
            }catch(e){}
        }


        //== 更新购物车价格/优惠等
        function updateGoodsInfo(rs,product) {
            if(!rs) return;
            try{
                product.getElement('.p-bagunit').innerHTML = rs.edit_ajax_data.bag_unit_str || '-';
                product.getElement('.p-price').innerHTML = rs.edit_ajax_data.s_price+'/'+rs.edit_ajax_data.bag_unit || '-';
                //product.getElement('.p-integral').innerHTML = Number(rs.edit_ajax_data.consume_score) || '-';
                product.getElement('.p-discount').innerHTML = rs.edit_ajax_data.discount || '-';
                product.getElement('.p-subtotal').innerHTML = rs.edit_ajax_data.buy_price || '-';
            }catch(e){}
            //console.log(rs.edit_ajax_data);
        }
        //== 更新商品促销
        function updateGoodsPromotion(rs, product) {
            if(!rs) return;
            var tmpl = '<li><b>[Акция]</b> {name}</li>';
            container.getElements('tbody tr.cart-product').each(function(item){
                var html = '';
                var ident = item.getElement('input[name=goods_ident]');
                if(!ident) return;
                var promoarea = item.getElement('.p-promotion ul');
                var identifier = ident.value;
                var item = rs[identifier];
                if(item && item.length) {
                    item.each(function(item){
                        if(item.cart_display) html += tmpl.substitute(item);
                    });
                    promoarea.innerHTML = html;
                }
            });
        }
        //== 更新订单信息
        function updateOrderInfo(rs) {
            //console.log(rs); //rs.discount_amount_order
            if(!rs) return;
            var order = $('order_price');
            if(order.getElement('.subtotal-integral')) order.getElement('.subtotal-integral').innerHTML = rs.subtotal_gain_score;
            if(order.getElement('.discount .price')) {
                if(rs.discount_amount_order) {
                    order.getElement('.discount').show();
                    order.getElement('.discount .price').innerHTML = rs.discount_amount_order;
                }
                else order.getElement('.discount').hide();
            }
            order.getElement('.goods .price').innerHTML = rs.subtotal_prefilter_after;
            order.getElement('.total .price b').innerHTML = rs.promotion_subtotal;
            // 更新订单总金额存储
            // Memory.set('cart_total_price', rs.promotion_subtotal);
        }
        //== 更新订单赠品区
        function updateOrderGift(rs) {
            var giftarea = $('order_gift');
            var tmpl = '<tr class="cart-item"><td><div class="p-pic"><a href="{url}"><img src="{thumbnail}" alt="{name}"></a></div></td><td class="p-info"><div class="p-title"><a href="{url}">{name}</a></div><div class="p-spec">{spec_info}</div></td><td class="p-price">{price}</td><td class="p-num">{quantity}</td><td colspan="4"></td></tr>';
            try{
                giftarea.getElements('.cart-item').destroy();
            }catch(e){}
            if(!rs) {
                return giftarea.hide();
            }
            var html = '';
            var item = rs;
            if(item && item.length) {
                item.each(function(item){
                    item.buy_price = item.price.buy_price || priceControl.format(0);
                    html += tmpl.substitute(item);
                });
            }
            giftarea.show().set('html', giftarea.get('html') +html);
        }
        <{if $cart_promotion_display == 'true'}>
        //== 更新订单促销
        function updateOrderPromotion(rs) {
            var area = $('order_promotion');
            if(!rs) area.hide();
            var tmpl = '<li><b>[Акция]</b> {name}</li>';
            var html = '';
            var promoarea = area.getElement('.content');
            var item = Object.values(rs);
            if(item && item.length) {
                area.show();
                item.each(function(item){
                    html += tmpl.substitute(item);
                });
            }
            promoarea.innerHTML = html;
        }
        //== 更新未使用的促销
        function updateUnusePromotion(rs){
            var area = $('unused_promotion');
            if(!rs) area.hide();
            var tmpl = '<li><b>[Акция]</b> {name}</li>';
            var html = '';
            var promoarea = area.getElement('.content');
            var item = Object.values(rs);
            if(item && item.length) {
                area.show();
                item.each(function(item){
                    html += tmpl.substitute(item);
                });
            };
            promoarea.innerHTML = html;
        }
        <{/if}>

 //== 为数量选择框绑定事件
    jQuery('.btn-decrease').hover(function(){
        var jinx_key= jQuery(this).parent().find('input').val();
        /* alert(jinx_key);*/
        if(jinx_key<=1){
            jQuery(this).css('cursor','not-allowed');
        }else{
            jQuery(this).css('cursor','pointer');
        }
    });
        function bindQuantityEvent(elements, callback) {
            elements = document.id(elements) || $$(elements);
            if(!elements || !elements.length) return;
            var value = '';
            elements.addEvents({
                //= 数量按钮
                'click:relay(.btn-decrease,.btn-increase)': function(e) {
                    var input = this.getParent().getElement('input');
                    value = +input.value;
                   /* input.value = this.hasClass('btn-decrease') ? value - 1 : value + 1;*/
                    if(this.hasClass('btn-decrease') && value>=2) {
                        value--;
                    }else{
                        jQuery('.btn-decrease').css('cursor','not-allowed');
                    }
                    if(this.hasClass('btn-increase')){
                        value++;
                    }
                    input.value=value;

                    callback && callback(input, value);
                    change_num();
                },
                //= 数量输入框
                'focus:relay(input)': function(e){
                    value = +this.value;
                },
                'change:relay(input)': function(e) {
                    callback && callback(this, value);
                }
            });
        }
        bindQuantityEvent('.p-quantity', setQuantity);

        $('main').addEvents({
                    'click': function(e){
                        var el = $(e.target);

                        //==点击document隐藏删除确认框
                        var dtc = $$('.dialog-tips-container')[0];
                        var target = $(document.body).retrieve('dialog-tip_show');
                        if(dtc && dtc.retrieve('instance') && !dtc.contains(el) && target && !target.contains(el)) dtc.retrieve('instance').hide();
                    },
                    //= 移除商品
                    'click:relay(.btn-delete)': function(e) {
                        var tr=this.getParent('tr');
                        var tab=this.getParent('.table-responsive');
                        var tr_id=tr.getElement('input').value;
                        var obj_idents=cart_obj_check(tr_id);
                        Dialog.tips(this, '<{t}>确定将商品从购物车中移除吗？<{/t}>', function(e){
                            if(e) {
                                var p = this.getParent('tr.p-adjunct') || this.getParent('.cart-item') || this.getParent('tr.item');
                                new Request({
                                    url:'<{link app=b2c ctl=site_cart act=remove}>',
                                    data: p.toQueryString()+"&obj_idents="+obj_idents+"&response_json=true",
                                    onRequest: function() {
                                        p.mask({html:'<{t}>处理中...<{/t}>','class':'cover',injectTo:document.body,position:true,effect:false, resize: false});
                                    },
                                    onComplete:function(rs) {
                                        rs = JSON.decode(rs);
                                        if(rs.is_empty) return location.reload();
                                        p.unmask();
                                        if(rs.error) return Message.error(rs.error);
                                        if(p.hasClass('item') && $('cart_exchange').getChildren().length == 2) $('cart_exchange').destroy();
                                        else p.destroy();
                                        linnum();
                                        change_num();

                                     /*   alert(jQuery(this).parents('tab').children('.cart-item').length);
                                        *//*if(jQuery(this).parrents('table').children('tr').length){

                                        }*/
                                        if(tab.getElements('.cart-check-obj').length<1){
                                            tab.remove();
                                        }
                                        updateCart(rs, p);

                                    }
                                }).post(p.get('data-product'));
                            }
                        }.bind(this));
                        document.body.store('dialog-tip_show', this);
                    },
                    //= 订单优惠收起/展开
                    'click:relay(.action-toggle)': function(e) {
                        e.stop();
                        this.set('text', this.hasClass('btn-collapse') ? '+' : '-').toggleClass('btn-collapse').toggleClass('btn-expand').getParent('h3').getNext('.content').toggle();
                    },
                    //= 凑单
                    'click:relay(.action-fororder)': function(e) {
                        e.stop();
                        var dialog = new Dialog('<{link app=b2c ctl=site_cart act=fororder}>', {
                            title: '<{t}>凑单商品<{/t}>',
                            width: 960,
                            height: 330,
                            modal:true,
                            async: 'ajax'
                        });
                    },
                <{if $login == 'nologin' && $env.conf.b2c.site.login_type == 'target'}>
                'click:relay(.action-settle)': function(e) {
            e.stop();
            miniPassport('<{link app=b2c ctl=site_cart act=loginBuy}>', function(dialog){
                this.removeClass('disabled');
            }.bind(this));
        },
        <{/if}>
        //= 清空购物车
        'click:relay(.action-clean)': function(e) {
            Dialog.confirm('<{t}>确定清空购物车吗？<{/t}>', function(e){
                if(e) {
                    new Request({
                        url:'<{link app=b2c ctl=site_cart act=remove}>',
                        data:'obj_type=all&response_json=true',
                        onRequest: function() {
                            container.mask({html:'<{t}>处理中...<{/t}>','class':'cover',position:true,effect:false, resize: false});
                        },
                        onSuccess:function(rs) {
                            rs = JSON.decode(rs);
                            container.unmask();
                            if(rs.error) return Message.error(rs.error);
                            location.reload();
                        }
                    }).post();
                }
            });
        },

        'click:relay(.action-settle)': function(e) {
            var cart_goods=cart_obj_check();
            if(cart_goods==""){
                alert('<{t}>请至少选择一件要付款的商品<{/t}>');
                e.stopPropagation();
                e.preventDefault();
            }

        },

        //= 取消收藏 by yyj 2015/12/21
        'click:relay(.btn-cancel)': function(e) {
            var tr=this.getParent('tr');
            var tr_id=tr.getElement('input').value;
            var obj_idents=cart_obj_check(tr_id);
            var goods_id = tr.getElement('input[name=goods_id]').value;
            var rel_url='<{link app=b2c ctl=site_member act=ajax_del_fav arg0="'+goods_id+'"}>';
            if(e) {
                var p = this.getParent('tr.p-adjunct') || this.getParent('.cart-item') || this.getParent('tr.item');
                new Request({
                    url:rel_url,
                    data: p.toQueryString()+"&obj_idents="+obj_idents+"&response_json=true",
                    onRequest: function() {
                        p.mask({html:'<{t}>处理中...<{/t}>','class':'cover',injectTo:document.body,position:true,effect:false, resize: false});
                    },
                    onComplete:function(rs) {
                        rs = JSON.decode(rs);
                        if(rs.error) return Message.error(rs.error);
                        location.reload();
                    }
                }).post(p.get('data-product'));
            }
            document.body.store('dialog-tip_show', this);
        },
    });
        //勾选商品同步价格 yhy
        $$('.cart-check-obj').addEvent('click',function(){
            jQuery(this).parents('.table-responsive').siblings('div').find('input[type=checkbox]').each(function(){
                jQuery(this).prop({checked:false});
            });
            if(jQuery(this).prop('checked')==false){
                jQuery(this).parents('.table-responsive').find('.all_checked').prop({checked:false});
            }else{
                var checkednum = 0;
                jQuery(this).parents('.table-responsive').find('.cart-check-obj').each(function(){
                    if(jQuery(this).prop('checked')==true){
                        checkednum+=1 ;
                    }
                });
                if(checkednum==jQuery(this).parents('.table-responsive').find('.cart-check-obj').length) {
                    jQuery(this).parents('.table-responsive').find('.all_checked').prop({checked: true});
                }
            }

            var p = this.getParent('tr');
            var obj_idents=cart_obj_check();
            new Request({
                url:'<{link app=b2c ctl=site_cart act=cart_obj_checked}>',
                data: p.toQueryString()+"&obj_idents="+obj_idents+"&response_json=true",
                onComplete: function(rs){
                    rs = JSON.decode(rs);
                    if(rs.success) {
                        updateCart(rs, p);
                    }
                }
            }).post();
        });
        //已选的结算框
        function cart_obj_check(obj){
            var check = $$(".cart-check-obj");
            var goods_idents = new Array();
            for(i = 0;i < check.length;i++){
                if(check[i].checked==true||check[i].checked=='true'){
                    if(obj&&obj==check[i].value){
                        continue;
                    }else{
                        goods_idents.push(check[i].value);
                    }
                }
            }
            return goods_idents;
        }
        //== 商品图片缩放
        if(Browser.ie6) {
            container.getElements('.p-pic img').each(function(img){
                img.zoomImg(80,80);
            });
        }
        <{/if}>

        //浏览历史
        withBrowserStore(function(browserStore) {
            var box = $('view_history');
            // $('clear_history').addEvent('click', function(){browserStore.clear('history');box.hide();});
            var myName = Cookie.read('UNAME');
            var key = "history_"+myName;
            browserStore.get(key, function(rs) {
                rs = JSON.decode(rs);
                var min = 1;
                if (!rs || rs.length <= min) return box.hide();

                var html = '';
                var template = '<div class="col-lg-3 col-md-3 col-sm-4 col-xs-12"><li class="item">';
                template += '<div class="p-pic">';
                template += '  <a href="<{link app=b2c ctl=site_product act=index arg0="{goodsId}"}>" target="_blank" title="{goodsName}" data-gid="{goodsId}"><img src="{goodsImg}" alt="{goodsName}" /></a>'.replace('index-', '');
                template += '</div>';
                template += '<div class="p-info">';
                template += '  <div class="item-title"><a href="<{link app=b2c ctl=site_product act=index arg0="{goodsId}"}>" target="_blank" title="{goodsName}">{goodsName}</a></div>'.replace('index-', '');
                template += '  <p class="item-price"><span>{price}</span></p>';
                template += '  <a href="<{link app=b2c ctl=site_product act=index arg0="{goodsId}"}>" target="_blank" class="btn btn-sm btn-primary"><{t}>立即购买<{/t}></a>'.replace('index-', '');
                template += '</div>';
                template += '</li></div>';

                var max = Math.min(rs.length, <{$setting.max|default:8}>);

                // rs.length > 1 && rs.sort(function(a, b) {
                //     return b['sortTime'] - a['sortTime'];
                // });

                rs.each(function(goods, index) {
                    if (index >= min && index <= max) html += template.substitute(goods);
                });

                box.getElement('ul').innerHTML = html;

                box.getElements('.p-pic a').each(function(item) {
                    var img = item.getElement('img');
                    // img.zoomImg(96,96);
                    img.onerror = function(){
                        imgRequest(item, img, rs, min, max);
                    }
                    if (!img.get('src')) {
                        imgRequest(item, img, rs, min, max);
                    }
                });
            });

            function imgRequest(el, img, rs, min, max) {
                var gid = el.get('data-gid');
                new Request.JSON({
                    url: "<{link app=b2c ctl=site_product act=picsJson}>",
                    onComplete: function(data) {
                        new Asset.image(data, {
                            onload: function() {
                                img.src = data;
                                img.zoomImg(96,96);
                            },
                            onerror: function() {
                                el.set('text', '<{t}>图片加载失败<{/t}>');
                            }
                        });

                        rs.map(function(goods, index) {
                            if (index >= min && index <= max && goods['goodsId'] == gid) return goods['goodsImg'] = data;
                        });
                        // var myName = Cookie.read('UNAME');
                        // var key = 'history_'+myName;
                        browserStore.set(key, JSON.encode(rs));
                    }
                }).get({'gids': gid});
            }
        });

        //window.addEvent('load',function(){
            var check = $$(".cart-check-obj");
            var goods_idents = new Array();
            for(i = 0;i < check.length;i++){
                if(check[i].checked==true||check[i].checked=='true'){
                    goods_idents.push(check[i].value);
                }
            }
            if(goods_idents!=''){
                new Request({
                    url:'<{link app=b2c ctl=site_cart act=cart_load_checked}>',
                    data:"obj_idents="+goods_idents+"&response_json=true",
                    onSuccess:function(rs){
                        rs = JSON.decode(rs);
                        updateCart(rs);
                    }
                }).post();
            }
       // });
        //商品全选结算 yhy
        if($$('.all_checked')){
            $$('.all_checked').addEvent('click',function(){
                if(this.checked==true){
//                    this.getElements('.cart-check-obj').each(function(e){
//                        e.checked=true;
//                    });

                    jQuery(this).parents('table').find('.cart-check-obj').each(function(){
                        jQuery(this).prop({checked:true});
                    });

                    jQuery(this).parents('.table-responsive').siblings('div').find('input[type=checkbox]').each(function(){
                        jQuery(this).prop({checked:false});
                    });

                    obj_idents=cart_obj_check();
                    new Request({
                        url:'<{link app=b2c ctl=site_cart act=cart_obj_all_checked}>',
                        data: "obj_idents="+obj_idents+"&response_json=true",
                        onComplete: function(rs){
                            rs = JSON.decode(rs);
                            if(rs.success) {
                                updateCart(rs);
                            }
                        }
                    }).post();
                }else{
//                    $$('.cart-check-obj').each(function(e){
//                        e.checked=false;
//                    });
                    jQuery(this).parents('table').find('.cart-check-obj').each(function(){
                        jQuery(this).prop({checked:false});
                    });
                    jQuery(this).parents('.table-responsive').siblings('div').find('input[type=checkbox]').each(function(){
                        jQuery(this).prop({checked:true});
                    });
                    obj_idents=cart_obj_check();
                    new Request({
                        url:'<{link app=b2c ctl=site_cart act=cart_obj_all_checked}>',
                        data: "obj_idents="+obj_idents+"&response_json=true",
                        onComplete: function(rs){
                            rs = JSON.decode(rs);
                            if(rs.success) {
                                updateCart(rs);
                            }
                        }
                    }).post();
                }
            });
        }
    })();

</script>